(Approved By AICTE, New Delhi Affiliated To VTU,Belagavi Recognized By UGC Under 2(f) & 12(B), Accredited By NBA & NAAC) NEAR ITPB, CHANNASANDRA, BENGALURU – 560 067 Affiliated to VTU, Belagavi Approved by AICTE, New Delhi Recognized by UGC under 2(f) & 12(B) Accredited by NBA & NAAC DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING V S EMESTER COMMUNICATION NETWORK LAB MVJ 20 AM L57 A CADEMIC Y EAR 202 2 – 202 3 (ODD) L ABORATORY M ANUAL N AM E OF THE S TUDENT : B RANCH : U NIVERSITY S EAT N O : S EMESTER & S ECTION : B ATCH : COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING VISION: To create an ambiance in excellence and provide innovative emerging programs in Computer Science and Engineering and to bring out future ready engineers equipped with technical expertise and strong ethical values. MISSION: 1. Concepts of Computing Discipline: To educate students at under graduate, postgraduate and doctoral levels in the fundamental and advanced concepts of computing discipline. 2. Quality Research: To provide strong theoretical and practical background across the Computer Science and Engineering discipline with the emphasis on computing technologies, quality research, consultancy and training's. 3. Continuous Teaching Learning: To promote a teaching learning process that brings advancem ents in Computer Science and Engineering discipline leading to new technologies and products. 4. Social Responsibility and Ethical Values: To inculcate professional behavior, innovative research Capabilities , leadership abilities and strong ethical values in the young minds so as to work with the commitment for the betterment of the society PROGRAM EDUCATIONAL OBJECTIVES (PEOs): PEO1: Current Industry Practices: Graduates will analyze real world problems and give solution using current industry practices in computing technology. PEO2: Research and Higher Studies: Graduates with strong foundation in mathematics and engineering fundamentals that will enable graduat es to pursue higher learning, R&D activities and consultancy. PEO3: Social Responsibility: Graduates will be professionals with ethics, who will provide industry growth and social transformation as responsible citizens. PEO4: Entrepreneur: Graduates will b e able to become entrepreneur to address social, technical and business challenges. COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] PROGRAM OUTCOMES (POs): 1. Engineering knowledge : Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. 2. Problem analysis : Identify, formulate, research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sci ences, and engineering sciences. 3. Desi gn/development of solutions : Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environm ental considerations. 4. Conduct investigations of complex problems : Use research - based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. 5. Modern tool usage : Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering activities with an understanding of the limitations. 6. The engineer and society : Apply rea soning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. 7. Environment and sustainability : Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development. 8. Ethics : Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. 9. Individual and team work : Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. 10. Communication : Communicate effectively on complex engineering activities with the enginee ring community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions. 11. Project management and finance : Demonstrate knowledge a nd understanding of the engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. 12. Life - long learning : Recognize the need for, and have the preparati on and ability to engage in independent and life - long learning in the broadest context of technological change. COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] PROGRAM SPECIFIC OUTCOMES (PSOs): PSO1: Programming: Ability to understand, analyze and develop computer programs in the areas related to al gorithms, system software, multimedia, web design, DBMS, and networking for efficient design of computer - based systems of varying complexity. PSO2: Practical Solution: Ability to practically provide solutions for real world problems with a broad range of p rogramming language and open source platforms in various computing domains. PSO3: Research: Ability to use innovative ideas to do research in various domains to solve societal problems. COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] COMMUNICATION NETWORK LABORATORY [As per Choice Based Credit System (CBCS) scheme] ( A cademic year 202 2 - 202 3 ) SEMESTER – V Subject Code : MVJ 20 CSL57 IA Marks 50 Number of Lecture Hours/Week 3 Exam Marks 50 Total Number of Lecture Hours 40 L : T : P :: 10 : 0 : 30 Exam Hours 03 CREDITS – 02 Course objective is to: This course will enable students to • To learn and use network commands. • To learn socket programming. • To implement and analyze various network protocols. • To learn and use simulation tools. • To use simulation tools to analyze the performance of various network protocols. Prerequisites: • Data Communication • Computer Networks Course Outcomes (CO’s): CO No CO’s C207.1 Analyze and Compare various networking protocols. C207.2 Demonstrate the working of different concepts of networking. C207.3 Implement, analyze and evaluate networking protocols in NS2 / NS3 C207.4 Student will become familiar with the network simulator C207.5 Students will get the concepts of error de tection & correction methods COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] Lab Experiments: Sl. No. Programs RBTL 1 Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping and traceroute PDUs using a network protocol analyzer and examine. L3 2 Write a program for error detecting code using CRC - CCITT (16 - bits). L3 3 Write a program to find the shortest path between vertices using bellman - ford algorithm. L3 4 Applications using TCP sockets like: a) Echo client and echo server b) Chat c) File Transfer L3 5 Simulation of DNS using UDP sockets. L3 6 Write a code for simulating ARP /RARP protocols. L3 7 Implementation of Stop and Wait Protocol and Sliding Window Protocol. L3 8 Write a program for congestion control using leaky bucket algorithm. L3 9 Simulate the transmission of ping messages/trace route over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion. L3 10 Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination. L3 11 Simulate simple ESS and with transmitting nodes in wireless LAN by simulation and determine the performance with respect to transmission of packets. L3 COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] 12 Implement three node point - to - point networks with duplex links between them. Set the queue size, vary the bandwidth, and find the number of packets dropped. L3 P O 1 P O 2 P O 3 P O 4 P O5 P O6 P O7 P O8 P O9 PO 10 PO 11 PO 12 P S O 1 P S O 2 C207.1 3 3 3 2 1 - - - - - - - 1 3 C207.2 3 3 2 2 1 - - - - - 1 - - - C207.3 3 3 2 2 1 - - - - - 1 - 3 - C207.4 3 3 2 2 1 - - - - - 1 - 3 - C207.5 3 2 2 2 1 - - - - - - - 1 3 Conduction of Practical Examination: 1. All laboratory experiments are to be included for practical examination. 2. Students are allowed to pick one experiment.. 3. Strictly follow the instructions as printed on the cover page of answer script 4. Marks distribution: Procedure + Conduction + Viva: 100 5. Change of experiment is allowed only once and marks allotted to the procedure part to be made zero Introduction to NS - 2: • Widely known as NS2, is simply an event driven simulation tool. • Useful in studying the dynamic nature of communication networks. • Simulation of wired as well as wireless netwo rk functions and protocols (e.g., routing algorithms, TCP, UDP) can be done using NS2. • In general, NS2 provides users with a way of specifying such network protocols and simulating their corresponding behaviours. • Basic Architecture of NS2 COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] Tcl scripting • Tcl is a general purpose scripting language. [Interpreter] • Tcl runs on most of the platforms such as Unix, Windows, and Mac. • The strength of Tcl is its simplicity. • It is not necessary to declare a data type for variable prior to the usage. Basics of TC L Syntax: command arg1 arg2 arg3 Hello World! puts stdout{Hello, World!} Hello, World! Variables Command Substitution set a 5 set len [string length foobar] set b $a set len [expr [string length foobar] + 9] Simple Arithmetic expr 7.2 / 4 Procedures proc Diag {a b} { set c [expr sqrt($a * $a + $b * $b)] return $c } puts “Diagonal of a 3, 4 right triangle is [Diag 3 4]” Output: Diagonal of a 3, 4 right triangle is 5.0 Loops while{$i < $n} { for {set i 0} {$i < $n} {incr i} { COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] . . . . . . } } Wired TCL Script Components Create the event scheduler Open new files & turn on the tracing Create the nodes Setup the links Configure the traffic type (e.g., TCP, UDP, etc) Set the time of tra ffic generation (e.g., CBR, FTP) Terminate the simulation NS Simulator Preliminaries. 1. Initialization and termination aspects of the ns simulator. 2. Definition of network nodes, links, queues and topology. 3. Definition of agents and of applications. 4. The nam visualization tool. 5. Tracing and random variables. Initialization and Termination of TCL Script in NS - 2 An ns simulation starts with the command Which is thus the first line in the tcl script? This line d eclares a new variable as using the set command, you can call this variable as you wish, In general people declares it as ns because it is an instance of the Simulator class, so an object the code[new Simulator] is indeed the installation of the class Simu lator using the reserved word new. In order to have output files with data on the simulation (trace files) or files used for visualization (nam files), we need to create the files using “open” command: #Open the Trace file #Open the NAM trace file set ns [new Simulator] set tracefile1 [open out.tr w] $ns trace - all $trace file1 set namfile [open out.nam w] $ns namtrace - all $namfile COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] The above creates a dta trace file called “out.tr” and a nam visualization trace file called “out.nam”.Within the tcl script,these files are not called explicitly by their names,but instead by pointers that are declared above and called “tracefile1” and “namfile” respectively.Remark that they begins with a # symbol.The second line open the file “out.tr” to be used for wri ting,declared with the letter “w”.The third line uses a simulator method called trace - all that have as parameter the name of the file where the traces will go. The last line tells the simulator to record all simulation traces in NAM input format.It also g ives the file name that the trace will be written to later by the command $ns flush - trace.In our case,this will be the file pointed at by the pointer “$namfile”,i.e the file “out.tr”. The termination of the program is done using a “finish” procedure. #Define a ‘finish’ procedure The word proc declares a procedure in this case called finish and without arguments. The word global is used to tell that we are using variables declared outside the procedure. The simulator method “ flush - trace” will dump the traces on the respective files . The tcl command “ close” closes the trace files defined before and exec executes the nam program for visualization. The command exit will ends the application and return the number 0 as status to the system. Zero is the default for a clean exit. Other val ues can be used to say that is a exit because something fails. At the end of ns program we should call the procedure “finish” and specify at what time the termination should occur. For example, will be used to call “ finish ” at time 125sec.Indeed,the at method of the simulator allows us to schedule events explicitly. P roc finish { } { global ns tracefile1 namfile $ns flush - trace Close $tracefile1 Close $namfile Exec nam out.nam & Exit 0 } $ns at 125.0 “finish” COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] The simulation can then begin using the command Definition of a network of links and nodes The way to define a node is The node is created which is printed by the variable n0. When we shall refer to that node in the script we shall thus write $n0. Once we define several nodes, we can define the links that connect them. An exa mple of a definition of a link is: Which means that $n0 and $n2 are connected using a bi - directional link that has 10ms of propagation delay and a capacity of 10Mb per sec for each direction. To define a directional link instead of a bi - directional one , we should replace “duplex - link” by “simplex - link”. In NS, an output queue of a node is implemented as a part of each link whose input is that node. The definition of the link then includes the way to handle overflow at that queue. In our case, if the bu ffer capacity of the output queue is exceeded then the last packet to arrive is dropped. Many alternative options exist, such as the RED (Random Early Discard) mechanism, the FQ (Fair Queuing), the DRR (Deficit Round Robin), the stochastic Fair Queuing (SF Q) and the CBQ (which including a priority and a round - robin scheduler). In ns, an output queue of a node is implemented as a part of each link whose input is that node. We should also define the buffer capacity of the queue related to each link. An example would be: Agents and Applications We need to define routing (sources, destinations) the agents (protocols) the application that use them. FTP over TCP $ns run set n0 [$ns node] $ns duplex - link $n0 $n2 10Mb 10ms DropTail #set Queue Size of link (n0 - n2) to 20 $ns queue - limit $n0 $n2 20 COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] TCP is a dynamic reliab le congestion control protocol. It uses Acknowledgements created by the destination to know whether packets are well received. There are number variants of the TCP protocol, such as Tahoe, Reno, NewReno, Vegas. The type of agent appears in the first line: The command $ns attach - agent $n0 $tcp defines the source node of the tcp connection. The command Defines the behavior of the destination node of TCP and assigns to it a pointer called sink. #Setup a UDP connection #setup a CBR over UDP connection The below shows the definition of a CBR application using a UDP agent The command $ns attach - agent $n4 $sink defines the destination node. The command $ns connect $tcp $sink finally makes the TCP connection between the source and destination nodes. set tcp [new Agent/TCP] set sink [new Agent /TCPSink ] set udp [new Agent/UDP] $ns attach - agent $n1 $udp set null [new Agent/Null] $ns attach - agent $n5 $null $ns connect $udp $null $udp set fid_2 set cbr [new Application/Traffic/CBR] $cbr attach - agent $udp $cbr set packetsize_ 100 $cbr set rate_ 0.01Mb $cbr set random_ false COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] TCP has many parameters with initial fixed defaults values that can be changed if mentioned explicitly. For example, the default TCP packet size has a size of 1000bytes.This can be changed to another value, say 552bytes, using the command $tcp set packetSi ze_ 552 When we have several flows, we may wish to distinguish them so that we can identify them with different colors in the visualization part. This is done by the command $tcp set fid_ 1 that assigns to the TCP connection a flow identification of “1”. We shall later give the flow identification of “2” to the UDP connection. CBR over UDP A UDP source and destination is defined in a similar way as in the case of TCP. Instead of defining the rate in the command $cbr set rate_ 0.01Mb, one can define the ti me interval between transmission of packets using the command. The packet size can be set to some value using Scheduling Events NS is a discrete event based simulation. The tcp script defines when event should occur. The initializing command set ns [new Simulator] creates an event scheduler, and events are then scheduled using the format: The scheduler is started when running ns that is through the com mand $ns run. The beginning and end of the FTP and CBR application can be done through the following command Structure of Trace Files $cbr set interval_ 0.005 $cbr set packetSize_ <packet size> $ns at <time> <event> $ns at 0.1 “$cbr start” $ns at 1.0 “ $ftp start” $ns at 124.0 “$ftp stop” $ns at 124.5 “$cbr stop” COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] When tracing into an output ASCII file, the trace is organized in 12 fields as follows in fig shown below, The meaning of the fields are: Event Time From Node To Node PKT Type PKT Size Flags Fid Src Addr Dest Addr Seq Num Pkt id 1. The first field is the event type. It is given by one of four possible symbols r, +, - , d which correspond respectively to receive (at the output of the link), enqueued, dequeued and dropped. 2. The second field gives the time at which the event occurs. 3. Gives the input node of the link at which the event occurs. 4. Gives the output node of the link at which the event occurs. 5. Gives the packet type (eg CBR or TCP) 6. Gives the packet size 7. Some flags 8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script one can further use this field for analysis purposes; it is also used when specifying stream color for the NAM display. 9. This is the source address given in the form of “node.port”. 10. This is the destination address, given in the same form. 11. This is the network layer protocol’s packet sequence number. Even though UDP implementations in a real network do not use sequence number, ns keeps track of UDP packet sequence number for analysis purposes 12. The last field shows the Unique id of the packet. XGRAPH The x graph program draws a graph on an x - display given data read from either data file or from standard input if no files are specified. It can display upto 64 independent data sets using different colors and line styles for each set. It annotates the graph wit h a title, axis labels, grid lines or tick marks, grid labels and a legend. Syntax: Options are listed here Xgraph [options] file - name COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] / - bd <color> (Border) This specifies the border color of the xgraph window. / - bg <color> (Background) This speci fies the background color of the xgraph window. / - fg<color> (Foreground) This specifies the foreground color of the xgraph window. / - lf <fontname> (LabelFont) All axis labels and grid labels are drawn using this font. / - t<string> (Title Text) This string is centered at the top of the graph. / - x <unit name> (XunitText) This is the unit name for the x - axis. Its default is “X”. / - y <unit name> (YunitText) This is the unit name for the y - axis. Its default is “Y”. Awk - An Advanced Awk is a programmable , pattern - matching, and processing tool available in UNIX. It Works equally well with text and numbers. Awk is not just a command, but a programming language too. In other words, awk utility is a pattern scanning and processing language. It searches one or more files to see if they contain lines that match specified patterns and then perform associated actions, such as writing the line to the standard output or incrementing a counter each time it finds a match. Syntax: Here, selection criteria filter input and select lines for the action component to act upon. The selection criteria are enclosed within single quotes and the action within the curly braces. Both the selection criteria and action forms an a wk program. Example: $ awk ‘/manager/ {print}’ emp.lst Variables Awk allows the user to use variables of there choice. You can now print a serial number, using the variable kount, and apply it those directors drawing a salary exceeding 6700: awk option ‘selection_criteria {action}’ fi le(s) COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] $ awk – F”|” ‘$3 == “director” && $6 > 6700 { kount =kount+1 printf “ %3f %20s % - 12s %d \ n”, kount,$2,$3,$6 }’ empn.lst THE – f OPTION: STORING awk PROGRAMS IN A FILE You should holds large awk programs in separate file and provide them with the awk extension for easier identification. Let’s first store the previous program in the file empawk.awk: $ cat empawk.awk Observe that this time we haven’t used quotes to enclose the awk program. You can now use awk with the – f filename option to obtain the same output: THE BEGIN AND END SECTIONS Awk statements are usually applied to all lines selected by the address, and if there are no addresses, then they are applied to every line of input. But, if you have to print something before p rocessing the first line, for example, a heading, then the BEGIN section can be used gainfully. Similarly, the end section useful in printing some totals after processing is over. The BEGIN and END sections are optional and take the form BEGIN {action} END {action} These two sections, when present, are delimited by the body of the awk program. You can use them to print a suitable heading at the beginning and the average salary at the end. BUILT - IN VARIABLES Awk has several built - in variables. T hey are all assigned automatically, though it is also possible for a user to reassign some of them. You have already used NR, which signifies the record number of the current line. We’ll now have a brief look at some of the other variable. The FS Variable : as stated elsewhere, awk uses a contiguous string of spaces as the default field delimiter. FS redefines this field separator, which in the sample database happens to be the |. When used at all, it must occur in the BEGIN section so that the body of the p rogram knows its value before it starts processing: BEGIN {FS=”|”} This is an alternative to the – F option which does the same thing. A wk – F”|” – f empawk.awk empn.lst COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] The OFS Variable : when you used the print statement with comma - separated arguments, each argument was separated from the other by a space. This is awk’s default output field separator, and can reassigned using the variable OFS in the BEGIN section: BEGIN { OFS=”~” } When you reassign this variable with a ~ (tilde), awk will use this character for delimiting the print arg uments. This is a useful variable for creating lines with delimited fields. The NF variable : NF comes in quite handy for cleaning up a database of lines that don’t contain the right number of fields. By using it on a file, say emp.lst, you can locate those lines not having 6 fields, and which have crept in due to faulty data entry: $awk ‘BEGIN {FS = “|”} NF! =6 {Print “Record No “, NR, “has”, “fields”}’empx.lst Experiment No :1 Learn to use commands like tcpdump, netstat, ifconfig, nslookup and tracerout e. AIM: To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute ping. PRE LAB DISCUSSION: Tcpdump: The tcpdump utility allows you to capture packets that flow within your network to assist in network troubleshooting. The following are several examples of using tcpdump with different options. Traffic is captured based on a specified filter. Netstat Netstat is a common command line TCP/IP networking available in most versions of Windows, Linux, UNIX a nd other operating systems. Netstat provides information and statistics about protocols in use and current TCP/IP network connections. COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] Ipconfig ipconfig is a console application designed to run from the Windows command prompt. This utility allows you to get the IP address information of a Windows computer. From the command prompt, type ipconfig to run the utility with default options. The output of the default command contains the IP address, network mask, and gateway for all physical and v irtual network adapter. Nslookup COMPUTER NETWORK LABORATORY [ MVJ20 AM L57 ] The nslookup (which stands for name server lookup ) command is a network utility program used to obtain information about internet servers. It finds name server information for domains by querying the Domain Name System. Trace route: Traceroute is a network diagnostic tool used to track the pathway taken by a packet on an IP network from source to destination. Traceroute also records the time taken for each hop the packet makes during its route to the destination Commands: Tcpdump: Display traffic between 2 hosts: To display all traffic between two hosts (represented by variables host1 and host2): # tcpdump host host1 and host2 Display traffic from a source or destination host only: To display traffic from onl y a source (src) or destination (dst) host: # tcpdump src host # tcpdump dst host Display traffic for a specific protocol Provide the protocol as an argument to display only traffic for a specific protocol, for example tcp, udp, icmp, arp tcpdump protocol For example to display traffic only for the tcp traffic : # tcpdump tcp Filtering based on source or destination port To filter based on a source or destination port: # tcpdump src port ftp # tcpdump dst port http